from azure.storage.blob._container_client import ContainerClient
from concurrent.futures import ThreadPoolExecutor, wait, ALL_COMPLETED


CONNECT_STRING= "DefaultEndpointsProtocol=https;AccountName=dataaggregate001;AccountKey=/pnKVSJdy/Ri0N5LXgdKqRvfqp4Qw5ITubK4MdaGGlE+pruX5iQJBqjVhMECkzBO0hTV5Y47wRDgNxU5TU8W0A==;EndpointSuffix=core.windows.net"
container_name = "test"
container = ContainerClient.from_connection_string(conn_str=CONNECT_STRING, container_name=container_name)
dir_list = container.walk_blobs("test/linnean_MMS/", delimiter='/')

def get_file(container,dir_list):
    for iterm in dir_list:
        print(iterm)
        # dir_list_son = container.walk_blobs(iterm.name, delimiter='/')
        # for son in dir_list_son:
        #     if 'txt' in son:
        #         with open(son,'rb') as f:
        #             s = f.read()
        #             print(s)
        #     else:
        #         print('null')


with ThreadPoolExecutor(max_workers=100) as executor:
        get_char_tasks = [
            executor.submit(get_file, container,iterm) for iterm in dir_list]
        wait(get_char_tasks, return_when=ALL_COMPLETED)